<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<div class="panel_container">
    <div class="panel">
        <form id="form_password" method="post" action="${ctx}/public/savePassword">
            <input type="hidden" name="id"/>
            <div class="panel_header">
                <div><h2>修改密码</h2></div>
            </div>
            <div class="panel_body">
                <div>
                    <div>
                        <div class="info_item"><span>旧密码:<b>*</b></span>
                            <input type="password" name="m_oldpassowrd" id="m_oldpassowrd" maxlength="100" class="text_medium"/>
                            <input type="hidden" name="m_curUserId" id="m_curUserId" value="${userId}" />
                        </div>
                    </div>
                    <div>
                        <div class="info_item"><span>新密码:<b>*</b></span>
                            <input type="password" name="m_newpassowrd" id="m_newpassowrd" maxlength="100" class="text_medium"/>
                        </div>
                    </div>
                    <div>
                        <div class="info_item"><span>密码确认:<b>*</b></span>
                            <input type="password" name="m_newpassowrd2" id="m_newpassowrd2" maxlength="100" class="text_medium"/>
                        </div>
                    </div>
                </div>

            </div>
            <div class="panel_footer">
                <div>
                    <input type="submit" value="保存" class="btn_blue" id="btn_save"/>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">

    $(function (){
        
        $("#form_password").validate({
            rules:{
                m_oldpassowrd: "required",
                m_newpassowrd:{
                    required: true,
                    minlength: 6,
                    password:true
                } ,
                m_newpassowrd2:{
                    required: true,
                    equalTo: "#m_newpassowrd"
                }
            },
            messages:{
                m_oldpassowrd: "旧密码必填",
                m_newpassowrd:{
                    required: "请填写密码",
                    minlength: "字符长度不能小于6个字符",
                    minlength: "密码必须包括至少含大写字母,小写字母,符号,数字中的三种"
                },
                m_newpassowrd2:{
                    required: "请再次输入密码",
                    equalTo: "密码不一致"
                }
            },

            submitHandler: function(form) {
                $(form).ajaxSubmit({
                    success: function(response) {
                        var c = $.parseJSON(response);

                        if(c.savePasswordFlag=="0"){
                            $.prompt("旧密码不匹配");
                        }else if(c.savePasswordFlag=="2"){
                            $.prompt(c.msg);
                        }
                        else{
                            $(':input','#form_password')
                                    .not(':button, :submit, :reset, :hidden')
                                    .val('')
                                    .removeAttr('checked')
                                    .removeAttr('selected');
                            $.prompt("保存成功");
                        }
                    },

                    error: function(response){
                        $.prompt("保存失败:"+response,"错误");
                    }
                });
            }
        });

    });


</script>
